<?php

class AdminModule extends CWebModule
{
	public function init()
	{
		$layout='//layouts/admin';
		$this->setImport(array(
			'admin.models.*',
			'admin.widget.*',
			'admin.components.*',
		));
	}

	public function beforeControllerAction($controller, $action)
	{
		if(parent::beforeControllerAction($controller, $action))
		{
			if(Yii::app()->user->isGuest){
				Yii::app()->controller->redirect(Yii::app()->controller->createUrl('/users/login'));
			}

			if(!Yii::app()->user->checkAccess(Users::ROLE_MODER)){
				Yii::app()->controller->redirect(Yii::app()->controller->createUrl('/main/index'));
			}

			return true;
		}else{
			return false;
		}
	}
}
